<?php
namespace App\Http\Controllers\admin;

use App\Http\Model\User;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Code;

class LoginController extends Controller
{
    //用户登录
    public function login()
    {
    	if($input = Input::all())
    	{
			$code = new Code;
			$_code = $code ->get();
    		if(strtoupper($input['code']) != $_code)
			{
				return back() -> with('msg','验证码错误!');
			}
            $user = User::first();
            if($user->user_name != $input['user_name'] || Crypt::decrypt($user->user_pass) != $input['user_pass'])
            {
                return back() -> with('msg', '用户名或者密码输入错误!');
            }
            session(['user'=>$user]);
            return redirect('Admin/index');
    	}else
        {
    		return view('Admin.login');
    	} 	
    }

    //生成验证码
    public function code($id)
    {
    	$code = new Code;
    	$code -> make();
    }

    //用户退出
    public function guit()
    {
        session(['user'=>null]);
        return redirect('Admin/login');
    }
}
